f = open("input.txt").readlines()
r = open("output.txt", 'w')
n = int(f[0])
a = [[] for i in range(n)]
for i in f[1:]:
    x, y = map(str, i.split())
    x = int(x)
    a[x-1].append(y)
s = ""
for i in range(n):
    for e in a[i]:
        s += str(i+1) + " " + e + "\n"
r.write(s)
r.close()